﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BOHVote.BLL;

namespace BOH.AccreditationSystem
{
    public partial class InterviewResults : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindApplyStyle();
            }
        }

        #region <<  Drop down list  >>
        public void BindApplyStyle()
        {
            DataSet dst = OtherClass.dstGetApplyStyle();
            BindDropDownList(drpApplyStyle, dst);
        }

        public void BindDropDownList(ListControl Controls, DataSet dst)
        {
            Controls.Items.Clear();
            ListItem list = new ListItem("请选择", "-1");
            Controls.Items.Add(list);
            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                ListItem itemlist = new ListItem(dr["dict_Display"].ToString(), dr["dict_Value"].ToString());
                Controls.Items.Add(itemlist);
            }
        }
        #endregion

        #region <<  binding GridView  >>

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            ResultDataBind();
        }

        public void ResultDataBind()
        {

            DataSet dst = InterviewClass.getAllResults(txtApplyName.Text.Trim(), "", "", "", drpPass.SelectedValue, drpApplyStyle.SelectedValue,"2008");//(string)Session["ApplyPeriod"]);
            ResultBind(dst);
        }

        public void ResultBind(DataSet dst)
        {
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
                if (AspNetPager1.RecordCount != 0)
                {
                    labNoRecord.Visible = false;
                    AspNetPager1.Visible = true;
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = dst.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;
                    InterviewResultsList.DataSource = pds;
                    InterviewResultsList.DataBind();
                }
                else
                {
                    InterviewResultsList.DataSource = null;
                    InterviewResultsList.DataBind();
                    AspNetPager1.Visible = false;
                    labNoRecord.Visible = true;
                }
            }
            else
            {
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
                InterviewResultsList.DataSource = null;
                InterviewResultsList.DataBind();
            }
        }

        protected void butSearch_Click(object sender, EventArgs e)
        {
            ResultDataBind();
        }

        #endregion
    }
}
